/**
 * Exception of libdragonscript
 * Copyright (C) 2009 Hajime Yoshimori <RoarLudros@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "DragonExcept"
#include "DragonInit"

#include <config.h>
#include <new>	// nothrow

using namespace std;

dragon::DragonMessage::msg_word dragon::DragonExcept::word = dragon::DragonMessage::normal;

dragon::DragonExcept::DragonExcept() {
  _msg  = new(nothrow) DragonMessage();
  _file = "";
  _can_recover = false;
  _line = 0;
}

dragon::DragonExcept::DragonExcept(const DragonMessage* msg, 
								   std::string file, 
								   bool can_recover,
								   unsigned int line) {
  _msg  = msg;
  _file = file;
  _can_recover = can_recover;
  _line = line;
}

dragon::DragonExcept::~DragonExcept() throw() {
  
}

string& dragon::DragonExcept::getFileName() {
  return _file;
}

unsigned int dragon::DragonExcept::getLineNum() {
  return _line;
}

const string& dragon::DragonExcept::getDescription() {
  static string msg;
  if(_msg) {
	msg = _msg->getMessage(word);
  } else {
	msg = d_("Couldn\'t allocate the memory for handling error message.");
  }
  return msg;
}
